home *** CD-ROM | disk | FTP | other *** search
/ TOS Silver 2000 / TOS Silver 2000.iso / programm / GNU_C++ / LIB / CFLIB-11.LZH / src / nkcc-pc.s < prev    next >
Encoding:
Text File  |  1998-03-29  |  24.2 KB  |  744 lines

  1. ****************************************************************************
  2. *
  3. *    Reduzierte NKCC für die CF-Lib/PureC
  4. *    Version für PureC
  5. *
  6. ****************************************************************************
  7.  
  8. ****************************************************************************
  9. *                          ASSEMBLER CONTROL SECTION                        *
  10. ****************************************************************************
  11.  
  12. VERSION         =    $0294            ; NKCC's version #
  13.  
  14. NKFf_FUNC        =    $8000
  15. NKFf_RESVD        =    $4000
  16. NKFf_NUM        =    $2000
  17. NKFf_CAPS        =    $1000
  18. NKFf_ALT        =    $0800
  19. NKFf_CTRL        =    $0400
  20. NKFf_SHIFT        =    $0300            ; both shift keys
  21.  
  22. NKFb_FUNC        =    15                ; function
  23. NKFb_RESVD        =    14                ; reserved, ignore it!
  24. NKFb_NUM        =    13                ; numeric pad
  25. NKFb_CAPS        =    12                ; CapsLock
  26. NKFb_ALT        =    11                ; Alternate
  27. NKFb_CTRL        =    10                ; Control
  28. NKFb_LSH        =    9                ; left Shift key
  29. NKFb_RSH        =    8                ; right Shift key
  30.  
  31. NK_UP            =    $01             ; cursor up
  32. NK_DOWN         =    $02             ; cursor down
  33. NK_RIGHT        =    $03             ; cursor right
  34. NK_LEFT         =    $04             ; cursor left
  35. NK_M_PGUP        =    $05             ; Mac: page up
  36. NK_M_PGDOWN     =    $06             ; Mac: page down
  37. NK_M_END        =    $07             ; Mac: end
  38. NK_INS            =    $0b             ; Insert
  39. NK_CLRHOME        =    $0c             ; Clr/Home
  40. NK_HELP         =    $0e             ; Help
  41. NK_UNDO         =    $0f             ; Undo
  42. NK_M_F11        =    $1a             ; Mac: function key #11
  43. NK_M_F12        =    $1c             ; Mac: function key #12
  44. NK_M_F14        =    $1d             ; Mac: function key #14
  45. NK_ENTER        =    $0a             ; Enter
  46. NK_DEL            =    $1f             ; Delete
  47.  
  48. ****************************************************************************
  49. *                                   EXPORT                                   *
  50. ****************************************************************************
  51.  
  52.                .globl    nkc_init             ; init NKCC
  53.                .globl    nkc_tos2n             ; TOS key code converter
  54.                .globl    nkc_n2tos             ; NKC to TOS key code converter
  55.                .globl   nkc_toupper          ; convert character to upper case
  56.                .globl   nkc_tolower          ; convert character to lower case
  57.  
  58. ****************************************************************************
  59. *                             LOCAL TEXT SECTION                            *
  60. ****************************************************************************
  61.  
  62.                .text
  63.  
  64. ****************************************************************************
  65. *
  66. *  nk_findscan: find scan code
  67. *
  68. ****************************************************************************
  69.  
  70. nk_findscan:   btst.l    #NKFb_NUM,d0         ; on numeric keypad?
  71.                beq.s    .search              ; no ->
  72.  
  73.                move     #$4a,d1              ; yes: try all numeric keypad
  74.                cmp.b    (a0,d1),d0             ;    scan codes first
  75.                beq.s    .found                 ; it matches ->
  76.  
  77.                move     #$4e,d1
  78.                cmp.b    (a0,d1),d0
  79.                beq.s    .found
  80.  
  81.                move     #$63,d1              ; block starts at $63
  82.  
  83. .numsearch:    cmp.b    (a0,d1),d0             ; match?
  84.                beq.s    .found                 ; yes ->
  85.  
  86.                addq     #1,d1                 ; next scan code
  87.                cmp        #$73,d1              ; block end at $72
  88.                blo.s    .numsearch             ; continue search ->
  89.  
  90. .search:       move     #1,d1                 ; start with first valid scan code
  91.  
  92. .mainsearch:   cmp.b    (a0,d1),d0             ; match?
  93.                beq.s    .found                 ; yes ->
  94.  
  95.                addq.b    #1,d1                 ; next scan code
  96.                cmp.b    #$78,d1              ; $78 = last valid scan code
  97.                blo.s    .mainsearch          ; continue search ->
  98.  
  99.                moveq.l    #0,d1                 ; not found
  100.                rts
  101.  
  102. .found:        tst        d1                     ; found; set CCR
  103.                rts
  104.  
  105.  
  106. ****************************************************************************
  107. *                             GLOBAL TEXT SECTION                           *
  108. ****************************************************************************
  109.  
  110.                .text
  111.  
  112. ****************************************************************************
  113. *
  114. *  nkc_init: initialize NKCC
  115. *
  116. ****************************************************************************
  117.  
  118. nkc_init:       
  119.  
  120. *------------- fetch addresses of TOS' key scan code translation tables
  121.  
  122.                moveq.l    #-1,d0                 ; the function is also used to
  123.                move.l    d0,-(sp)             ; change the addresses; values
  124.                move.l    d0,-(sp)             ; of -1 as new addresses tell
  125.                move.l    d0,-(sp)             ; XBIOS not to change them
  126.                move     #$10,-(sp)             ; Keytbl
  127.                trap     #14                  ; XBIOS
  128.                lea        $e(sp),sp             ; clean stack
  129.  
  130.                move.l    d0,a0                 ; ^key table structure
  131.                move.l    (a0)+,pkey_unshift     ; get ^unshifted table
  132.                move.l    (a0)+,pkey_shift     ; get ^shifted table
  133.                move.l    (a0),pkey_caps         ; get ^CapsLock table
  134.  
  135. *------------- exit
  136.  
  137. .exit:           move     #VERSION,d0          ; load version #
  138.                rts                             ; bye
  139.  
  140. ****************************************************************************
  141. *
  142. *  nkc_tconv: TOS key code converter
  143. *
  144. ****************************************************************************
  145.  
  146. nkc_tos2n:       movem.l    d3/d4,-(sp)          ; save registers
  147.  
  148. *------------- separate TOS key code
  149.  
  150.                move.l    d0,d1                 ; TOS key code
  151.                swap     d1                     ; .W = scan code and flags
  152.                move     d1,d2                 ; copy
  153.                move     #$ff,d3              ; and-mask
  154.                and        d3,d0                 ; .B = ASCII code
  155.                and        d3,d1                 ; .B = scan code
  156.                beq        .tos306              ; scancode=zero (key code created
  157.                                              ;    by ASCII input of TOS 3.06)? ->
  158.                and        #$1f00,d2             ; .W = key flags (in high byte)
  159.  
  160. *------------- decide which translation table to use
  161.  
  162.                move     d2,d3                 ; key flags
  163.                and        #NKFf_SHIFT,d3         ; isolate bits for shift keys
  164.                beq.s    .ktab1                 ; shift key pressed? no->
  165.  
  166.                move.l    pkey_shift,a0         ; yes: use shift table
  167.                bra.s    .ktab3                 ; ->
  168.  
  169. .ktab1:        btst.l    #NKFb_CAPS,d2         ; CapsLock?
  170.                beq.s    .ktab2                 ; no->
  171.  
  172.                move.l    pkey_caps,a0         ; yes: use CapsLock table
  173.                bra.s    .ktab3                 ; ->
  174.  
  175. .ktab2:        move.l    pkey_unshift,a0      ; use unshifted table
  176.  
  177. *------------- check if scan code is out of range
  178. *
  179. * Illegal scancodes can be used to produce 'macro key codes'. Their format is:
  180. *
  181. * - the scancode must be $84 or larger (should be $ff to work properly with old
  182. *    versions of Mag!x)
  183. * - the ASCII code must be in the range $20...$ff (values below are set to $20
  184. *    by NKCC)
  185. * - Alternate and Control are not used for the normalized key code. However,
  186. *    if at least one of them is non-zero, then the numeric keypad flag will be
  187. *    set in the resulting key code.
  188. *
  189.  
  190. .ktab3:        cmp.b    #$84,d1              ; illegal scan code?
  191.                blo.s    .ktab4                 ; no ->
  192.  
  193.                move     d2,d1                 ; flags
  194.                and        #NKFf_ALT|NKFf_CTRL,d1    ; Alternate or Control?
  195.                beq.s    .special             ; no ->
  196.  
  197.                or        #NKFf_NUM,d0         ; yes: set numeric keypad flag
  198.                and        #NKFf_CAPS|NKFf_SHIFT,d2   ; mask off both flags
  199.  
  200. .special:       or        d2,d0                 ; combine with ASCII code
  201.                or        #NKFf_FUNC|NKFf_RESVD,d0   ; set function and resvd
  202.                cmp.b    #$20,d0              ; ASCII code in range?
  203.                bhs        .exit                 ; yes ->
  204.  
  205.                move.b    #$20,d0              ; no: use minimum
  206.                bra        .exit                 ; ->
  207.  
  208. *------------- check if Alternate + number: they have simulated scan codes
  209.  
  210. .ktab4:        cmp.b    #$78,d1              ; scan code of Alt + number?
  211.                blo.s    .scan1                 ; no->
  212.  
  213.                sub.b    #$76,d1              ; yes: calculate REAL scan code
  214.                move.b    (a0,d1),d0             ; fetch ASCII code
  215.                or        #NKFf_ALT,d2         ; set Alternate flag
  216.                bra        .cat_codes             ; -> add flag byte and exit
  217.  
  218. *------------- check if exception scan code from cursor keypad
  219.  
  220. .scan1:        lea        xscantab,a1          ; ^exception scan code table
  221.  
  222. .search_scan:  move     (a1)+,d3             ; NKC and scan code
  223.                bmi.s    .tabend              ; <0? end of table reached ->
  224.  
  225.                cmp.b    d1,d3                 ; scan code found?
  226.                bne.s    .search_scan         ; no: continue search ->
  227.  
  228.                lsr        #8,d3                 ; .B = NKC
  229.                moveq.l    #0,d0                 ; mark: key code found
  230.                bra.s    .scan2                 ; ->
  231.  
  232. .tabend:       moveq.l    #0,d3                 ; no NKC found yet
  233.  
  234. *------------- check if rubbish ASCII code and erase it, if so
  235.  
  236. .scan2:        move.b    (a0,d1),d4             ; ASCII code from translation table
  237.                cmp.b    #32,d0                 ; ASCII returned by TOS < 32?
  238.                bhs.s    .scan3                 ; no -> can't be rubbish
  239.  
  240.                cmp.b    d4,d0                 ; yes: compare with table entry
  241.                beq.s    .scan3                 ; equal: that's ok ->
  242.  
  243.                moveq.l    #0,d0                 ; not equal: rubbish! clear it
  244.  
  245. *------------- check if ASCII code could only be produced via Alternate key
  246. *               combination
  247.  
  248. .scan3:        tst.b    d0                     ; ASCII code valid?
  249.                beq.s    .scan4                 ; no ->
  250.  
  251.                cmp.b    d4,d0                 ; compare with table entry
  252.                beq.s    .scan4                 ; equal: normal key ->
  253.  
  254.                and        #!NKFf_ALT,d2         ; no: clear Alternate flag
  255.  
  256. *------------- check if ASCII code found yet, and set it, if not
  257.  
  258. .scan4:        tst.b    d0                     ; found?
  259.                bne.s    .scan5                 ; yes ->
  260.  
  261.                move.b    d3,d0                 ; no: use code from exception table
  262.                bne.s    .scan5                 ; now valid? yes ->
  263.  
  264.                move.b    d4,d0                 ; no: use code from transl. table
  265.  
  266. *------------- check special case: delete key
  267.  
  268. .scan5:        cmp.b    #127,d0              ; ASCII code of Delete?
  269.                bne.s    .scan6                 ; no ->
  270.  
  271.                move.b    #NK_DEL,d0             ; yes: set according NKC
  272.  
  273. *------------- check if key is on numeric keypad (via scan code)
  274.  
  275. .scan6:        cmp.b    #$4a,d1              ; numeric pad scan code range?
  276.                beq.s    .numeric             ; yes ->
  277.  
  278.                cmp.b    #$4e,d1
  279.                beq.s    .numeric             ; yes ->
  280.  
  281.                cmp.b    #$63,d1
  282.                blo.s    .scan7                 ; no ->
  283.  
  284.                cmp.b    #$72,d1
  285.                bhi.s    .scan7                 ; no ->
  286.  
  287. .numeric:       or        #NKFf_NUM,d2         ; yes: set numeric bit
  288.  
  289. *------------- check if "function key" and set bit accordingly
  290.  
  291. .scan7:        cmp.b    #32,d0                 ; ASCII code less than 32?
  292.                bhs.s    .scan8                 ; no ->
  293.  
  294.                or        #NKFf_FUNC,d2         ; yes: set function bit
  295.  
  296. *------------- check special case: Return or Enter key
  297.  
  298.                cmp.b    #13,d0                 ; Return or Enter key?
  299.                bne.s    .scan8                 ; no ->
  300.  
  301.                btst.l    #NKFb_NUM,d2         ; yes: from the numeric pad?
  302.                beq.s    .scan8                 ; no -> it's Return, keep code
  303.  
  304.                moveq.l    #NK_ENTER,d0         ; yes: it's Enter; new code
  305.  
  306. *------------- check if function key (F1-F10) via scan code
  307.  
  308. .scan8:        cmp.b    #$54,d1              ; shift + function key?
  309.                blo.s    .scan9                 ; no ->
  310.  
  311.                cmp.b    #$5d,d1
  312.                bhi.s    .scan9                 ; no ->
  313.  
  314.                sub.b    #$54-$3b,d1          ; yes: scan code for unshifted key
  315.                move     d2,d3                 ; shift flags
  316.                and        #NKFf_SHIFT,d3         ; any shift key flag set?
  317.                bne.s    .scan9                 ; yes ->
  318.                or        #NKFf_SHIFT,d2         ; no: set both flags
  319.  
  320. .scan9:        cmp.b    #$3b,d1              ; (unshifted) function key?
  321.                blo.s    .cat_codes             ; no ->
  322.  
  323.                cmp.b    #$44,d1
  324.                bhi.s    .cat_codes             ; no ->
  325.  
  326.                move.b    d1,d0                 ; yes: calc NKC
  327.                sub.b    #$2b,d0
  328.  
  329. *------------- final flag handling; mix key code (low byte) and flag byte
  330.  
  331. .cat_codes:    move.l    pkey_shift,a0         ; ^shifted table
  332.                move.b    (a0,d1),d3             ; get shifted ASCII code
  333.                or        d2,d0                 ; mix flags with key code
  334.                bmi.s    .scan10              ; result is "function key"? ->
  335.  
  336.                and        #NKFf_CTRL+NKFf_ALT,d2    ; Control or Alternate pressed?
  337.                bne.s    .scan11              ; yes ->
  338.  
  339. .scan10:       move.l    pkey_unshift,a0      ; ^unshifted table
  340.                cmp.b    (a0,d1),d3             ; shifted ASCII = unshifted ASCII?
  341.                beq.s    .scan12              ; yes ->
  342.  
  343.                bra.s    .exit                 ; no ->
  344.  
  345. .scan11:       or        #NKFf_FUNC,d0         ; Alt/Ctrl + char: set function bit
  346.                move.l    pkey_caps,a0         ; ^CapsLock table
  347.                cmp.b    (a0,d1),d3             ; shifted ASCII = CapsLocked ASCII?
  348.                bne.s    .exit                 ; no ->
  349.  
  350.                move.b    d3,d0                 ; yes: use shifted ASCII code
  351.  
  352. .scan12:       or        #NKFf_RESVD,d0         ; yes: nkc_cmp() has to check
  353.  
  354. *------------- restore registers and exit
  355.  
  356. .exit:           tst        d0                     ; set CCR
  357.                movem.l    (sp)+,d3/d4          ; restore registers
  358.                rts                             ; bye
  359.  
  360. *------------- special handling for key codes created by TOS' 3.06 ASCII input
  361.  
  362. .tos306:       and        #NKFf_CAPS,d2         ; isolate CapsLock flag
  363.                or        d2,d0                 ; merge with ASCII code
  364.                movem.l    (sp)+,d3/d4          ; restore registers
  365.                rts                             ; bye
  366.  
  367. ****************************************************************************
  368. *
  369. *  nkc_n2tos: convert normalized key codes back to TOS format
  370. *
  371. ****************************************************************************
  372.  
  373. nkc_n2tos:       move     d0,d1                 ; normalized key code
  374.                and        #NKFf_FUNC|NKFf_ALT|NKFf_CTRL,d1 ; isolate flags
  375.                cmp        #NKFf_FUNC,d1         ; only function flag set?
  376.                bne.s    .ktab0                 ; no ->
  377.  
  378.                cmp.b    #$20,d0              ; ASCII code >= $20?
  379.                blo.s    .ktab0                 ; no ->
  380.  
  381. *------------- macro key
  382.  
  383.                move     d0,d1                 ; keep normalized key code
  384.                and.l    #NKFf_CAPS|NKFf_SHIFT,d0   ; isolate usable flags
  385.                btst.l    #NKFb_NUM,d1         ; numeric keypad flag set?
  386.                beq.s    .mackey              ; no ->
  387.  
  388.                or        #NKFf_ALT|NKFf_CTRL,d0    ; yes: set Alternate + Control
  389.  
  390. .mackey:       or.b     #$ff,d0              ; scan code always $ff
  391.                swap     d0                     ; flags and scan code in upper word
  392.                move.b    d1,d0                 ; ASCII code
  393.                bra        .exit                 ; ->
  394.  
  395. *------------- select system key table to use
  396.  
  397. .ktab0:        move     d0,d1                 ; normalized key code
  398.                and        #NKFf_SHIFT,d1         ; isolate bits for shift keys
  399.                beq.s    .ktab1                 ; shift key pressed? no->
  400.  
  401.                lea        n_to_scan_s,a1         ; ^default translation table
  402.                move.l    pkey_shift,a0         ; yes: use shift table
  403.                bra.s    .ktab3                 ; ->
  404.  
  405. .ktab1:        lea        n_to_scan_u,a1         ; ^unshifted translation table
  406.                btst.l    #NKFb_CAPS,d0         ; CapsLock?
  407.                beq.s    .ktab2                 ; no->
  408.  
  409.                move.l    pkey_caps,a0         ; yes: use CapsLock table
  410.                bra.s    .ktab3                 ; ->
  411.  
  412. .ktab2:        move.l    pkey_unshift,a0      ; use unshifted table
  413.  
  414. *------------- handling for ASCII codes >= 32
  415.  
  416. .ktab3:        cmp.b    #32,d0                 ; ASCII code < 32?
  417.                blo.s    .lowascii             ; yes ->
  418.  
  419.                bsr        nk_findscan          ; find scan code
  420.                bne.s    .found                 ; found ->
  421.  
  422.                btst.l    #NKFb_FUNC,d0         ; function flag set?
  423.                beq.s    .notfound             ; no ->
  424.  
  425.                move.l    a0,d1                 ; save a0
  426.                lea        tolower,a0             ; ^upper->lower case table
  427.                moveq.l    #0,d2                 ; clear for word operation
  428.                move.b    d0,d2                 ; ASCII code
  429.                move.b    (a0,d2),d0             ; get lowercased ASCII code
  430.                move.l    d1,a0                 ; restore a0
  431.                bsr        nk_findscan          ; try to find scan code again
  432.                bne.s    .found                 ; found ->
  433.  
  434. *------------- unknown source: treat key code as it was entered using the
  435. *               TOS 3.06 direct ASCII input
  436.  
  437. .notfound:       moveq.l    #0,d1                 ; not found: clear for word op.
  438.                move.b    d0,d1                 ; unchanged ASCII code
  439.                and        #$1f00,d0             ; keep shift flags only
  440.                swap     d0                     ; -> high word (scan code = 0)
  441.                move     d1,d0                 ; low word: ASCII code
  442.                bra        .exit                 ; ->
  443.  
  444. *------------- handling for ASCII codes < 32
  445.  
  446. .lowascii:       btst.l    #NKFb_FUNC,d0         ; function key?
  447.                bne.s    .func                 ; yes ->
  448.  
  449.                and        #$10ff,d0             ; clear all flags except CapsLock
  450.                bra.s    .notfound             ; ->
  451.  
  452. .func:           moveq.l    #0,d1                 ; clear for word operation
  453.                move.b    d0,d1                 ; ASCII code (0...$1f)
  454.                move     d1,d2                 ; copy
  455.                move.b    (a1,d1),d1             ; get scan code
  456.                bne.s    .getascii             ; valid? ->
  457.  
  458.                moveq    #0,d0                 ; invalid key code!! return 0
  459.                bra        .exit                 ; ->
  460.  
  461. .getascii:       lea        n_to_scan_u,a1         ; ^unshifted translation table
  462.                move.b    (a1,d2),d2             ; get scan code from unshifted tab.
  463.                move.b    (a0,d2),d0             ; get ASCII from system's table
  464.  
  465. * register contents:
  466. *
  467. * d0.b           ASCII code
  468. * d1.b           scan code
  469. * d0.hb        NKCC flags
  470. *
  471.  
  472. .found:        move     d0,d2                 ; flags and ASCII code
  473.                and        #$1f00,d0             ; isolate shift flags
  474.                move.b    d1,d0                 ; merge with scan code
  475.                swap     d0                     ; -> high byte
  476.                clr        d0                     ; erase low word
  477.                move.b    d2,d0                 ; restore ASCII code
  478.  
  479. *------------- handling for Control key flag
  480.  
  481.                btst.l    #NKFb_CTRL,d2         ; control key flag set?
  482.                beq.s    .alternate             ; no ->
  483.  
  484.                cmp.b    #$4b,d1              ; scan code = "cursor left"?
  485.                bne.s    .scanchk2             ; no ->
  486.  
  487.                add.l    #$280000,d0          ; change scan code to $73
  488.                clr.b    d0                     ; erase ASCII code
  489.                bra.s    .exit                 ; ->
  490.  
  491. .scanchk2:       cmp.b    #$4d,d1              ; scan code = "cursor right"?
  492.                bne.s    .scanchk3             ; no ->
  493.  
  494.                add.l    #$270000,d0          ; change scan code to $74
  495.                clr.b    d0                     ; erase ASCII code
  496.                bra.s    .exit                 ; ->
  497.  
  498. .scanchk3:       cmp.b    #$47,d1              ; scan code = "ClrHome"?
  499.                bne.s    .ascchk              ; no ->
  500.  
  501.                add.l    #$300000,d0          ; change scan code to $77
  502. ; keep ASCII code in this case! What a mess...
  503.                bra.s    .exit                 ; ->
  504.  
  505. .ascchk:       lea        asc_trans,a0         ; ^ASCII translation table
  506.  
  507. .ascloop:       move     (a0)+,d1             ; get next entry
  508.                beq.s    .noctrlasc             ; end of table ->
  509.  
  510.                cmp.b    d0,d1                 ; ASCII code found?
  511.                bne.s    .ascloop             ; no -> continue search
  512.  
  513.                lsr        #8,d1                 ; yes: get translated code
  514.                move.b    d1,d0                 ; use it
  515.                bra.s    .exit                 ; ->
  516.  
  517. .noctrlasc:    and.b    #$1f,d0              ; mask off upper 3 bits
  518.                bra.s    .exit                 ; ->
  519.  
  520. *------------- handling for Alternate key flag
  521.  
  522. .alternate:    btst.l    #NKFb_ALT,d2         ; alternate key flag set?
  523.                beq.s    .exit                 ; no ->
  524.  
  525.                cmp.b    #2,d1                 ; top row on main keyboard?
  526.                blo.s    .alphachk             ; no ->
  527.  
  528.                cmp.b    #$d,d1
  529.                bhi.s    .alphachk             ; no ->
  530.  
  531.                add.l    #$760000,d0          ; yes: change scan code
  532.                clr.b    d0                     ; and erase ASCII code
  533.                bra.s    .exit                 ; ->
  534.  
  535. .alphachk:       cmp.b    #'A',d0              ; alpha-characters?
  536.                blo.s    .exit                 ; no ->
  537.  
  538.                cmp.b    #'z',d0
  539.                bhi.s    .exit                 ; no ->
  540.  
  541.                cmp.b    #'Z',d0
  542.                bls.s    .ascii0              ; yes ->
  543.  
  544.                cmp.b    #'a',d0
  545.                blo.s    .exit                 ; no ->
  546.  
  547. .ascii0:       clr.b    d0                     ; alpha-character: clear ASCII code
  548.  
  549. .exit:           tst.l    d0                     ; set CCR
  550.                rts                             ; bye
  551.  
  552. ****************************************************************************
  553. *
  554. *  nkc_toupper: convert character to upper case
  555. *
  556. ****************************************************************************
  557.  
  558. nkc_toupper:   lea      toupper,a0           ; ^upper case translation table
  559.                and      #$ff,d0              ; high byte = 0 for word operation
  560.                move.b   (a0,d0),d0           ; convert
  561.                rts                           ; bye
  562.  
  563.  
  564. ****************************************************************************
  565. *
  566. *  nkc_tolower: convert character to lower case
  567. *
  568. ****************************************************************************
  569.  
  570. nkc_tolower:   lea      tolower,a0           ; ^lower case translation table
  571.                and      #$ff,d0              ; high byte = 0 for word operation
  572.                move.b   (a0,d0),d0           ; convert
  573.                rts                           ; bye
  574.  
  575.  
  576. ****************************************************************************
  577. *                             LOCAL DATA SECTION                            *
  578. ****************************************************************************
  579.  
  580.                .data
  581.  
  582. *  exception scan code table for cursor block keys
  583. *
  584. *  first entry.B:  NKCC key code
  585. *  second entry.B: scan code returned by TOS
  586. *
  587. *  the table is terminated with both entries -1
  588.  
  589. xscantab:       .dc.b    NK_UP        ,  $48     ; cursor up
  590.                .dc.b    NK_DOWN     ,  $50     ; cursor down
  591.                .dc.b    NK_LEFT     ,  $4b     ; cursor left
  592.                .dc.b    NK_LEFT     ,  $73     ; Control cursor left
  593.                .dc.b    NK_RIGHT    ,  $4d     ; cursor right
  594.                .dc.b    NK_RIGHT    ,  $74     ; Control cursor right
  595.                .dc.b    NK_M_PGUP    ,  $49     ; Mac: page up
  596.                .dc.b    NK_M_PGDOWN ,  $51     ; Mac: page down
  597.                .dc.b    NK_M_END    ,  $4f     ; Mac: end
  598.                .dc.b    NK_INS        ,  $52     ; Insert
  599.                .dc.b    NK_CLRHOME    ,  $47     ; ClrHome
  600.                .dc.b    NK_CLRHOME    ,  $77     ; Control ClrHome
  601.                .dc.b    NK_HELP     ,  $62     ; Help
  602.                .dc.b    NK_UNDO     ,  $61     ; Undo
  603.                .dc.b    NK_M_F11    ,  $45     ; Mac: F11
  604.                .dc.b    NK_M_F12    ,  $46     ; Mac: F12
  605.                .dc.b    NK_M_F14    ,  $37     ; Mac: F14
  606.                .dc.w    -1
  607.  
  608.  
  609. *  lower case to upper case conversion table
  610. *  (array of 256 unsigned bytes)
  611.  
  612. toupper:
  613.                .dc.b    $00,$01,$02,$03,$04,$05,$06,$07
  614.                .dc.b    $08,$09,$0a,$0b,$0c,$0d,$0e,$0f
  615.                .dc.b    $10,$11,$12,$13,$14,$15,$16,$17
  616.                .dc.b    $18,$19,$1a,$1b,$1c,$1d,$1e,$1f
  617.                .dc.b    " !",$22,"#$%&",$27,"()*+,-./0123456789:;<=>?"
  618.                .dc.b    "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[",$5c,"]^_"
  619.                .dc.b    "`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~"
  620.                .dc.b    "ÇÜÉâÄÀÅÇêëèïîìÄÅÉÆÆôÖòûùÿÖÜ¢£¥ßƒ"
  621.                .dc.b    "áíóúÑѪº¿⌐¬½¼¡«»ÃÕØØŒŒÀÃÕ¨´†¶©®™"
  622.                .dc.b    "ijIJאבגדהוזחטיכלמנסעפצקרשתןךםףץ§∧∞"
  623.                .dc.b    "αβΓπΣσµτΦΘΩδ∮ϕ∈∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²³¯"
  624.  
  625.  
  626. *  upper case to lower case conversion table
  627. *  (array of 256 unsigned bytes)
  628.  
  629. tolower:
  630.                .dc.b    $00,$01,$02,$03,$04,$05,$06,$07
  631.                .dc.b    $08,$09,$0a,$0b,$0c,$0d,$0e,$0f
  632.                .dc.b    $10,$11,$12,$13,$14,$15,$16,$17
  633.                .dc.b    $18,$19,$1a,$1b,$1c,$1d,$1e,$1f
  634.                .dc.b    " !",$22,"#$%&",$27,"()*+,-./0123456789:;<=>?"
  635.                .dc.b    "@abcdefghijklmnopqrstuvwxyz[",$5c,"]^_"
  636.                .dc.b    "`abcdefghijklmnopqrstuvwxyz{|}~"
  637.                .dc.b    "çüéâäàåçêëèïîìäåéææôöòûùÿöü¢£¥ßƒ"
  638.                .dc.b    "áíóúññªº¿⌐¬½¼¡«»ãõøøœœàãõ¨´†¶©®™"
  639.                .dc.b    "ijIJאבגדהוזחטיכלמנסעפצקרשתןךםףץ§∧∞"
  640.                .dc.b    "αβΓπΣσµτΦΘΩδ∮ϕ∈∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²³¯"
  641.  
  642.  
  643. *  ASCII code translation table for Control key
  644. *
  645. *  first entry.B:  modified ASCII code returned by TOS
  646. *  second entry.B: original ASCII code as stored in key table
  647. *
  648. *  The table is terminated with both entries 0
  649.  
  650. asc_trans:       .dc.b    0,'2'                 ; Control '2' becomes ASCII 0
  651.                .dc.b    $1e,'6'              ; Control '6' becomes ASCII $1e
  652.                .dc.b    $1f,'-'              ; Control '-' becomes ASCII $1f
  653.                .dc.b    $a,$d                 ; Control Return/Enter: $d -> $a
  654.                .dc.w    0                     ; terminator
  655.  
  656.  
  657. *  normalized key code -> scan code translation table
  658. *  for unshifted key codes
  659. *  indexed by function code (NK_...)
  660.  
  661. n_to_scan_u:   .dc.b    $00                  ; invalid key code
  662.                .dc.b    $48                  ; cursor up
  663.                .dc.b    $50                  ; cursor down
  664.                .dc.b    $4d                  ; cursor right
  665.                .dc.b    $4b                  ; cursor left
  666.                .dc.b    $49                  ; Mac: page up
  667.                .dc.b    $51                  ; Mac: page down
  668.                .dc.b    $4f                  ; Mac: end
  669.                .dc.b    $0e                  ; Backspace
  670.                .dc.b    $0f                  ; Tab
  671.                .dc.b    $72                  ; Enter
  672.                .dc.b    $52                  ; Insert
  673.                .dc.b    $47                  ; ClrHome
  674.                .dc.b    $1c                  ; Return
  675.                .dc.b    $62                  ; Help
  676.                .dc.b    $61                  ; Undo
  677.                .dc.b    $3b                  ; function key #1
  678.                .dc.b    $3c                  ; function key #2
  679.                .dc.b    $3d                  ; function key #3
  680.                .dc.b    $3e                  ; function key #4
  681.                .dc.b    $3f                  ; function key #5
  682.                .dc.b    $40                  ; function key #6
  683.                .dc.b    $41                  ; function key #7
  684.                .dc.b    $42                  ; function key #8
  685.                .dc.b    $43                  ; function key #9
  686.                .dc.b    $44                  ; function key #10
  687.                .dc.b    $45                  ; Mac: F11
  688.                .dc.b    $01                  ; Esc
  689.                .dc.b    $46                  ; Mac: F12
  690.                .dc.b    $37                  ; Mac: F14
  691.                .dc.b    $00                  ; reserved!
  692.                .dc.b    $53                  ; Delete
  693.  
  694. *  normalized key code -> scan code translation table
  695. *  for shifted key codes
  696. *  indexed by function code (NK_...)
  697.  
  698. n_to_scan_s:   .dc.b    $00                  ; invalid key code
  699.                .dc.b    $48                  ; cursor up
  700.                .dc.b    $50                  ; cursor down
  701.                .dc.b    $4d                  ; cursor right
  702.                .dc.b    $4b                  ; cursor left
  703.                .dc.b    $49                  ; Mac: page up
  704.                .dc.b    $51                  ; Mac: page down
  705.                .dc.b    $4f                  ; Mac: end
  706.                .dc.b    $0e                  ; Backspace
  707.                .dc.b    $0f                  ; Tab
  708.                .dc.b    $72                  ; Enter
  709.                .dc.b    $52                  ; Insert
  710.                .dc.b    $47                  ; ClrHome
  711.                .dc.b    $1c                  ; Return
  712.                .dc.b    $62                  ; Help
  713.                .dc.b    $61                  ; Undo
  714.                .dc.b    $54                  ; function key #1
  715.                .dc.b    $55                  ; function key #2
  716.                .dc.b    $56                  ; function key #3
  717.                .dc.b    $57                  ; function key #4
  718.                .dc.b    $58                  ; function key #5
  719.                .dc.b    $59                  ; function key #6
  720.                .dc.b    $5a                  ; function key #7
  721.                .dc.b    $5b                  ; function key #8
  722.                .dc.b    $5c                  ; function key #9
  723.                .dc.b    $5d                  ; function key #10
  724.                .dc.b    $45                  ; Mac: F11
  725.                .dc.b    $01                  ; Esc
  726.                .dc.b    $46                  ; Mac: F12
  727.                .dc.b    $37                  ; Mac: F14
  728.                .dc.b    $00                  ; reserved!
  729.                .dc.b    $53                  ; Delete
  730.  
  731. ****************************************************************************
  732. *                              LOCAL BSS SECTION                            *
  733. ****************************************************************************
  734.  
  735.                .bss
  736.  
  737. pkey_unshift:  .ds.l    1                     ; ^unshifted key table
  738. pkey_shift:    .ds.l    1                     ; ^shifted key table
  739. pkey_caps:       .ds.l    1                     ; ^CapsLock table
  740.  
  741.                .even
  742.  
  743. * End Of File
  744.